<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="招标方" prop="tenderer">
        <el-input
          v-model="queryParams.tenderer"
          placeholder="请输入招标方"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理机构" prop="agency">
        <el-input
          v-model="queryParams.agency"
          placeholder="请输入代理机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="招标平台" prop="tenderPlatform">
        <el-input
          v-model="queryParams.tenderPlatform"
          placeholder="请输入招标平台"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属专业" prop="major">
        <el-input
          v-model="queryParams.major"
          placeholder="请输入所属专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技术负责人" prop="headOfTech">
        <el-input
          v-model="queryParams.headOfTech"
          placeholder="请输入技术负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开标时间" prop="tenderDate">
        <el-date-picker clearable
          v-model="queryParams.tenderDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择开标时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="网址" prop="url">
        <el-input
          v-model="queryParams.url"
          placeholder="请输入网址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预计竞争单位" prop="expectedCompetitor">
        <el-input
          v-model="queryParams.expectedCompetitor"
          placeholder="请输入预计竞争单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="中标金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入中标金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否总承包
value = 1；是
value = 0；否" prop="whetherGeneralContract">
        <el-input
          v-model="queryParams.whetherGeneralContract"
          placeholder="请输入是否总承包
value = 1；是
value = 0；否"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否中标
value = 1；是
value = 0；否" prop="whetherWinBid">
        <el-input
          v-model="queryParams.whetherWinBid"
          placeholder="请输入是否中标
value = 1；是
value = 0；否"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否完成
value = 1；是
value = 0；否" prop="whetherComplete">
        <el-input
          v-model="queryParams.whetherComplete"
          placeholder="请输入是否完成
value = 1；是
value = 0；否"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="保证金金额是否退还
value = 1；是
value = 0；否" prop="whetherRefund">
        <el-input
          v-model="queryParams.whetherRefund"
          placeholder="请输入保证金金额是否退还
value = 1；是
value = 0；否"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退款金额" prop="refundAmount">
        <el-input
          v-model="queryParams.refundAmount"
          placeholder="请输入退款金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退款联系方式" prop="refundContact">
        <el-input
          v-model="queryParams.refundContact"
          placeholder="请输入退款联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="投标截止时间" prop="bidDeadline">
        <el-date-picker clearable
          v-model="queryParams.bidDeadline"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择投标截止时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="标书id" align="center" prop="tenderId" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="招标方" align="center" prop="tenderer" />
      <el-table-column label="代理机构" align="center" prop="agency" />
      <el-table-column label="招标平台" align="center" prop="tenderPlatform" />
      <el-table-column label="所属专业" align="center" prop="major" />
      <el-table-column label="技术负责人" align="center" prop="headOfTech" />
      <el-table-column label="开标时间" align="center" prop="tenderDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tenderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="网址" align="center" prop="url" />
      <el-table-column label="预计竞争单位" align="center" prop="expectedCompetitor" />
      <el-table-column label="中标金额" align="center" prop="amount" />
      <el-table-column label="是否总承包
value = 1；是
value = 0；否" align="center" prop="whetherGeneralContract" />
      <el-table-column label="是否中标
value = 1；是
value = 0；否" align="center" prop="whetherWinBid" />
      <el-table-column label="是否完成
value = 1；是
value = 0；否" align="center" prop="whetherComplete" />
      <el-table-column label="保证金金额是否退还
value = 1；是
value = 0；否" align="center" prop="whetherRefund" />
      <el-table-column label="退款金额" align="center" prop="refundAmount" />
      <el-table-column label="退款联系方式" align="center" prop="refundContact" />
      <el-table-column label="上传通知" align="center" prop="uploadNotification" />
      <el-table-column label="投标截止时间" align="center" prop="bidDeadline" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bidDeadline, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="招标方" prop="tenderer">
          <el-input v-model="form.tenderer" placeholder="请输入招标方" />
        </el-form-item>
        <el-form-item label="代理机构" prop="agency">
          <el-input v-model="form.agency" placeholder="请输入代理机构" />
        </el-form-item>
        <el-form-item label="招标平台" prop="tenderPlatform">
          <el-input v-model="form.tenderPlatform" placeholder="请输入招标平台" />
        </el-form-item>
        <el-form-item label="所属专业" prop="major">
          <el-input v-model="form.major" placeholder="请输入所属专业" />
        </el-form-item>
        <el-form-item label="技术负责人" prop="headOfTech">
          <el-input v-model="form.headOfTech" placeholder="请输入技术负责人" />
        </el-form-item>
        <el-form-item label="开标时间" prop="tenderDate">
          <el-date-picker clearable
            v-model="form.tenderDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开标时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="网址" prop="url">
          <el-input v-model="form.url" placeholder="请输入网址" />
        </el-form-item>
        <el-form-item label="预计竞争单位" prop="expectedCompetitor">
          <el-input v-model="form.expectedCompetitor" placeholder="请输入预计竞争单位" />
        </el-form-item>
        <el-form-item label="中标金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入中标金额" />
        </el-form-item>
        <el-form-item label="是否总承包
value = 1；是
value = 0；否" prop="whetherGeneralContract">
          <el-input v-model="form.whetherGeneralContract" placeholder="请输入是否总承包
value = 1；是
value = 0；否" />
        </el-form-item>
        <el-form-item label="是否中标
value = 1；是
value = 0；否" prop="whetherWinBid">
          <el-input v-model="form.whetherWinBid" placeholder="请输入是否中标
value = 1；是
value = 0；否" />
        </el-form-item>
        <el-form-item label="是否完成
value = 1；是
value = 0；否" prop="whetherComplete">
          <el-input v-model="form.whetherComplete" placeholder="请输入是否完成
value = 1；是
value = 0；否" />
        </el-form-item>
        <el-form-item label="保证金金额是否退还
value = 1；是
value = 0；否" prop="whetherRefund">
          <el-input v-model="form.whetherRefund" placeholder="请输入保证金金额是否退还
value = 1；是
value = 0；否" />
        </el-form-item>
        <el-form-item label="退款金额" prop="refundAmount">
          <el-input v-model="form.refundAmount" placeholder="请输入退款金额" />
        </el-form-item>
        <el-form-item label="退款联系方式" prop="refundContact">
          <el-input v-model="form.refundContact" placeholder="请输入退款联系方式" />
        </el-form-item>
        <el-form-item label="上传通知" prop="uploadNotification">
          <el-input v-model="form.uploadNotification" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="投标截止时间" prop="bidDeadline">
          <el-date-picker clearable
            v-model="form.bidDeadline"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择投标截止时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo } from "@/api/system/info";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 基本信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        tenderer: null,
        agency: null,
        tenderPlatform: null,
        major: null,
        headOfTech: null,
        tenderDate: null,
        url: null,
        expectedCompetitor: null,
        amount: null,
        whetherGeneralContract: null,
        whetherWinBid: null,
        whetherComplete: null,
        whetherRefund: null,
        refundAmount: null,
        refundContact: null,
        uploadNotification: null,
        bidDeadline: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询基本信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        tenderId: null,
        projectName: null,
        tenderer: null,
        agency: null,
        tenderPlatform: null,
        major: null,
        headOfTech: null,
        tenderDate: null,
        url: null,
        expectedCompetitor: null,
        amount: null,
        whetherGeneralContract: null,
        whetherWinBid: null,
        whetherComplete: null,
        whetherRefund: null,
        refundAmount: null,
        refundContact: null,
        uploadNotification: null,
        bidDeadline: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.tenderId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const tenderId = row.tenderId || this.ids
      getInfo(tenderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.tenderId != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const tenderIds = row.tenderId || this.ids;
      this.$modal.confirm('是否确认删除基本信息编号为"' + tenderIds + '"的数据项？').then(function() {
        return delInfo(tenderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
